<template>
	<view class="coupons-page">
		<!-- 自定义导航栏 -->
		<view class="nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="nav-content">
				<view class="nav-back" @click="goBack">
					<text class="back-icon">‹</text>
				</view>
				<text class="nav-title">优惠券</text>
				<view class="nav-right">
					<text class="nav-icon">⋯</text>
					<text class="nav-icon">○</text>
				</view>
			</view>
		</view>

		<!-- 标签栏 -->
		<view class="tab-bar">
			<view 
				class="tab-item" 
				:class="{ active: currentTab === 0 }" 
				@click="switchTab(0)"
			>
				待使用
			</view>
			<view 
				class="tab-item" 
				:class="{ active: currentTab === 1 }" 
				@click="switchTab(1)"
			>
				已使用
			</view>
			<view 
				class="tab-item" 
				:class="{ active: currentTab === 2 }" 
				@click="switchTab(2)"
			>
				已过期
			</view>
		</view>

		<!-- 内容区域 -->
		<view class="content-area">
			<!-- 待使用优惠券 -->
			<template v-if="currentTab === 0">
				<view 
					class="coupon-card" 
					v-for="(item, index) in unusedCoupons" 
					:key="index"
				>
					<view class="coupon-content">
						<view class="coupon-top">
							<view class="coupon-left-info">
								<text class="coupon-limit">{{ item.limit }}</text>
								<text class="coupon-condition">{{ item.condition }}</text>
							</view>
							<view class="coupon-value">
								<text class="currency">¥</text>
								<text class="amount">{{ item.amount }}</text>
							</view>
						</view>
						<view class="coupon-divider"></view>
						<view class="coupon-bottom">
							<text class="coupon-validity">有效期至: {{ item.validity }}</text>
							<text class="coupon-action" @click="useCoupon(index)">去使用 ></text>
						</view>
					</view>
				</view>
			</template>

			<!-- 已使用优惠券 -->
			<template v-if="currentTab === 1">
				<view 
					class="coupon-card used" 
					v-for="(item, index) in usedCoupons" 
					:key="index"
				>
					<view class="coupon-content">
						<view class="coupon-top">
							<view class="coupon-left-info">
								<text class="coupon-limit">{{ item.limit }}</text>
								<text class="coupon-condition">{{ item.condition }}</text>
							</view>
							<view class="coupon-value">
								<text class="currency">¥</text>
								<text class="amount">{{ item.amount }}</text>
							</view>
						</view>
						<view class="coupon-divider"></view>
						<view class="coupon-bottom">
							<text class="coupon-validity">有效期至: {{ item.validity }}</text>
							<text class="coupon-action used-text">已使用 ></text>
						</view>
					</view>
				</view>
			</template>

			<!-- 已过期优惠券 -->
			<template v-if="currentTab === 2">
				<view 
					class="coupon-card expired" 
					v-for="(item, index) in expiredCoupons" 
					:key="index"
				>
					<view class="coupon-content">
						<view class="coupon-top">
							<view class="coupon-left-info">
								<text class="coupon-limit">{{ item.limit }}</text>
								<text class="coupon-condition">{{ item.condition }}</text>
							</view>
							<view class="coupon-value">
								<text class="currency">¥</text>
								<text class="amount">{{ item.amount }}</text>
							</view>
						</view>
						<view class="coupon-divider"></view>
						<view class="coupon-bottom">
							<text class="coupon-validity">有效期至: {{ item.validity }}</text>
							<text class="coupon-action expired-text">已过期 ></text>
						</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		ref
	} from 'vue';

	// 状态栏高度
	const statusBarHeight = ref(0);

	// 当前选中的标签
	const currentTab = ref(0);

	// 待使用优惠券列表
	const unusedCoupons = ref([
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		},
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		},
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		}
	]);

	// 已使用优惠券列表
	const usedCoupons = ref([
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		},
		{
			amount: 50,
			condition: '满500元可用',
			limit: '仅限于XX洗车店使用',
			validity: '2023.06.01—2023.12.31'
		}
	]);

	// 已过期优惠券列表
	const expiredCoupons = ref([
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		},
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		},
		{
			amount: 20,
			condition: '满200元可用',
			limit: '仅限于XX加油站使用',
			validity: '2020.04.11—2023.05.11'
		}
	]);

	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};

	// 切换标签
	const switchTab = (index) => {
		currentTab.value = index;
	};

	// 使用优惠券
	const useCoupon = (index) => {
		uni.showToast({
			title: '跳转到使用页面',
			icon: 'none'
		});
		// 这里可以跳转到使用优惠券的页面
	};

	onLoad(() => {
		// 获取状态栏高度
		const systemInfo = uni.getSystemInfoSync();
		statusBarHeight.value = systemInfo.statusBarHeight;
	});
</script>

<style scoped>
	.coupons-page {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 导航栏 */
	.nav-bar {
		background-color: #007AFF;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 1000;
	}

	.nav-content {
		height: 44px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
	}

	.nav-back {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.back-icon {
		color: #fff;
		font-size: 48rpx;
		font-weight: 300;
		line-height: 1;
	}

	.nav-title {
		color: #fff;
		font-size: 36rpx;
		font-weight: 500;
		flex: 1;
		text-align: center;
	}

	.nav-right {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.nav-icon {
		color: #fff;
		font-size: 40rpx;
	}

	/* 标签栏 */
	.tab-bar {
		margin-top: calc(44px + var(--status-bar-height, 0px));
		background-color: #007AFF;
		display: flex;
		align-items: center;
		padding: 0 30rpx;
		height: 88rpx;
		box-sizing: border-box;
	}

	.tab-item {
		flex: 1;
		text-align: center;
		font-size: 32rpx;
		color: rgba(255, 255, 255, 0.7);
		position: relative;
		padding: 20rpx 0;
	}

	.tab-item.active {
		color: #fff;
		font-weight: 500;
	}

	.tab-item.active::after {
		content: '';
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		width: 60rpx;
		height: 4rpx;
		background-color: #fff;
		border-radius: 2rpx;
	}

	/* 内容区域 */
	.content-area {
		padding: 30rpx;
		background-color: #f5f5f5;
		min-height: calc(100vh - 44px - var(--status-bar-height, 0px) - 88rpx);
	}

	/* 优惠券卡片 */
	.coupon-card {
		background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
		border-radius: 16rpx;
		margin-bottom: 30rpx;
		overflow: visible;
		position: relative;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
	}

	.coupon-card.used {
		background: #e0e0e0;
	}

	.coupon-card.expired {
		background: #e0e0e0;
	}

	/* 优惠券左侧和右侧的圆形缺口效果 */
	.coupon-card::before {
		content: '';
		position: absolute;
		left: -20rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
		background-color: #f5f5f5;
		border-radius: 50%;
		z-index: 1;
	}

	.coupon-card::after {
		content: '';
		position: absolute;
		right: -20rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
		background-color: #f5f5f5;
		border-radius: 50%;
		z-index: 1;
	}

	.coupon-content {
		padding: 30rpx;
		position: relative;
		z-index: 2;
	}

	/* 顶部区域 */
	.coupon-top {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		margin-bottom: 20rpx;
	}

	.coupon-left-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		gap: 12rpx;
	}

	.coupon-limit {
		font-size: 28rpx;
		color: rgba(255, 255, 255, 0.8);
	}

	.coupon-condition {
		font-size: 36rpx;
		color: #fff;
		font-weight: 600;
	}

	.coupon-card.used .coupon-limit,
	.coupon-card.expired .coupon-limit {
		color: rgba(0, 0, 0, 0.5);
	}

	.coupon-card.used .coupon-condition,
	.coupon-card.expired .coupon-condition {
		color: #666;
	}

	.coupon-value {
		display: flex;
		align-items: baseline;
		color: #fff;
	}

	.coupon-card.used .coupon-value,
	.coupon-card.expired .coupon-value {
		color: #666;
	}

	.currency {
		font-size: 32rpx;
		font-weight: 500;
	}

	.amount {
		font-size: 72rpx;
		font-weight: bold;
		line-height: 1;
	}

	/* 分隔线 */
	.coupon-divider {
		height: 0;
		border-top: 2px dashed rgba(255, 255, 255, 0.3);
		margin: 20rpx 0;
		position: relative;
	}

	.coupon-card.used .coupon-divider,
	.coupon-card.expired .coupon-divider {
		border-top: 2px dashed rgba(0, 0, 0, 0.1);
	}

	/* 底部区域 */
	.coupon-bottom {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.coupon-validity {
		font-size: 28rpx;
		color: rgba(255, 255, 255, 0.8);
	}

	.coupon-card.used .coupon-validity,
	.coupon-card.expired .coupon-validity {
		color: rgba(0, 0, 0, 0.5);
	}

	.coupon-action {
		font-size: 28rpx;
		color: #fff;
	}

	.coupon-action.used-text {
		color: rgba(0, 0, 0, 0.5);
	}

	.coupon-action.expired-text {
		color: rgba(0, 0, 0, 0.5);
	}
</style>
